/**
 * 百度地图 xtype = cceafmappanel
 *
 * @module Ext-ux-cceaf-control
 * @class cceaf.control.MapPanel
 * @extends Ext.grid.Panel
 * @since 1.0
 */
Ext.define('cceaf.control.MapPanel', {
	extend : 'Ext.panel.Panel',
	alias : 'widget.cceafmappanel',
	
	level : 7,
	marks : [],
	
	setPostion_xy : function(x, y, a, b, c) {
		var point = new BMap.Point(x, y);
		this.setPostion(point);
		var marker = new BMap.Marker(point);
		// 创建标注
		this.map.clearOverlays();
		this.map.addOverlay(marker);
		// 将标注添加到地图中
		this.marks.push(marker);
		if (this.level < 7) {
			marker.hide();
		}
		// marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画

		// ===============点击一次
		marker.addEventListener("click", function(v) {
			var sContent1 = "<h4 style='margin:0 0 5px 0;padding:0.2em 0'></h4>" + "<p style='margin:0;line-height:1.2;font-size:13px;'>" + "设备名称：" + a + "<br />" + "设备类型：" + b + "<br />" + "设备状态：" + c + "</p>";
			var infoWindow = new BMap.InfoWindow(sContent1);
			// 创建信息窗口对象
			marker.openInfoWindow(infoWindow);
		});
		// ===============点击二次
		var sContent2 = "<object type='application/x-shockwave-flash' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width=400 height=200><param name='movie' value='flvplayer.swf' />" + "<param name='quality' value='high'><param name='allowfullscreen' value='true'><param name='allowscriptaccess' value='always' />" + "<param name='flashvars' value='file=1.flv&autostart=true' />" + "<embed type='application/x-shockwave-flash' src='flvplayer.swf' width=400 height=200 allowscriptaccess='always'" + "allowfullscreen=true flashvars='file=1.flv&autostart=true' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object>";
		var infoWindow1 = new BMap.InfoWindow(sContent2);
		// 创建信息窗口对象
		marker.addEventListener("dblclick", function() {
			this.openInfoWindow(infoWindow1);
		});
	},
	
	setPostion : function(point) {
		this.map.centerAndZoom(point, this.level);
	},
	
	onRender : function(ct, position) {
		if (!this.mapId) {
			var node = ct.dom.childNodes[position];

			this.mapId = node.childNodes[0];
			for (var j = 0, len = this.mapId.childNodes.length; j < len; j++) {
				this.mapId.removeChild(this.mapId.childNodes[j]);
			}
			this.mapId.style.width = '100%';
			this.mapId.style.height = '100%';
			this.map = new BMap.Map(this.mapId.id);
			// 创建Map实例
			// 到达7级时显示一下
			this.map.enableScrollWheelZoom();
			var obj = this;
			this.map.addEventListener("zoomend", function() {
				obj.level = this.getZoom();
				for (var i = 0; i < obj.marks.length; i++) {
					if (this.getZoom() > 7) {
						obj.marks[i].show();
					} else {
						obj.marks[i].hide();
					}
				}
			});
			// 获取当前地图级别
			/*
			 * ggetzoom() { return g_Zoom = gMap.getZoom(); }
			 */

			this.map.addControl(new BMap.NavigationControl());
			// 添加默认缩放平移控件
			this.setPostion(this.postion);
			this.map.enableScrollWheelZoom();
			// 启用滚轮放大缩小
		}
		cceaf.control.MapPanel.superclass.onRender.apply(this, arguments);
	},
	
	listeners : {
		afterrender : function() {
			setTimeout(function() {
				var all = document.all ? document.all : document.getElementsByTagName('*');
				for (var e = 0; e < all.length; e++) {
					if (all[e].className) {
						if (all[e].className.indexOf('anchorBL') != -1) {
							all[e].style.display = 'none';
						}
					}
				}
			}, 800);
		}
	}
}); 